﻿using Developer.Code;
using Developer.Service;
using Super.Framework.Common;
using Super.Framework.Common.Web;
using Super.Framework.EF;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace Developer.Web.Areas.Admin.Controllers
{
    public class ReviewsController : BaseController
    {
        // GET: Admin/Reviews
        public ActionResult Index()
        {
            var pageIndex = Query.Value("page").ToInt(1);
            var key = Query.Value("name");
            int pageCount;
            int itemCount;

            var comments = ReviewService.GetAll().Where(a => a.IsAbort == false);
            if (key.IsNotNullOrEmpty())
            {
                comments = comments.Where(a => a.Title.Contains(key) || a.SubTitle.Contains(key));
                ViewBag.Name = key;
            }
            var items = comments.OrderByDescending(u => u.CreateTime)
              .Page(out itemCount, out pageCount, pageSize: PageSize, pageIndex: pageIndex);
            ViewBag.pageCount = pageCount;
            ViewBag.itemCount = itemCount;
            return View(items);
        }


        [HttpPost]
        public ActionResult Delete()
        {
            var id = Query.Value("rid").ToInt();
            ReviewService.Remove(id);
            ShowMsg("删除成功", MessageItemType.Right);
            return Redirect("/admin/reviews/Index");
        }
    }
}